{include file="public/nheader" /}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="agentid" lay-filter="agentid" lay-search>
                                <option value="">选择代理商</option>
                                {foreach $agent as $v}
                                <option value="{$v.id}" {if !empty(input('get.agentid')) &&
                                    input('get.agentid')==$v.id}selected{/if}>{$v.nickname}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="type" lay-verify="">
                                <option value="">代理类型</option>
                                <option value="2" {if !empty(input('get.type')) && input('get.type')==2}selected{/if}>
                                    城市代理</option>
                                <option value="3" {if !empty(input('get.type')) && input('get.type')==3}selected{/if}>
                                    区域代理</option>
                                <option value="4" {if !empty(input('get.type')) && input('get.type')==4}selected{/if}>
                                    街道代理</option>
                                <option value="5" {if !empty(input('get.type')) && input('get.type')==5}selected{/if}>
                                    划分代理</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="province" lay-filter="province">
                                <option value="">请选择搜索省份</option>
                                {foreach $province as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.province')) &&
                                    input('get.province')==$v.area_code}selected{/if}>{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="city" lay-filter="city">
                                <option value="">请选择搜索城市</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="area" lay-filter="area">
                                <option value="">请选择搜索区域</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="street" lay-filter="street">
                                <option value="">请选择搜索街道</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <!-- // 打开添加页面 -->
                        <button class="layui-btn icon-btn layui-btn-warm" lay-maxmin="true" lay-open=""
                            data-title="批量添加" data-area="60%,80%"
                            data-url="/agent/agentarea_edit2?agentid={:input('get.agentid')}">批量添加
                        </button>
                        <button class="layui-btn icon-btn" lay-maxmin="true" lay-open="" data-title="添加"
                            data-area="60%,80%" data-url="/agent/agentarea_edit?agentid={:input('get.agentid')}">添加
                        </button>
                        <!-- // 删除所有 -->
                        <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/agent/agentarea_del">批量删除
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    {{#  if(d.type ==5){ }}
    <a class="layui-table-text" lay-open data-title="划分" data-area="100%,100%" data-url="/agent/agentarea_quan?id={{d.id}}" >划分</a>
    <div class="layui-divider layui-divider-vertical"></div>
    {{#  } }}
<a class="layui-table-text" data-url="/agent/agentarea_del?id={{d.id}}" lay-event="del">删除</a>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {

        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        form.on("submit(formSearch)", function (post) {
            // 获取用户id
            if (post.field.province || post.field.city || post.field.area || post.field.street) {
                if (!post.field.type) {
                    layer.error('请填写合伙人类型');
                    return false;
                }
            }
            layui.$.get("{:url('')}", post.field, function (res) {
                if (res.code == 200) {
                    table.reload("lay-tableList", {
                        page: {
                            curr: 1
                        },
                        where: post.field
                    })
                }
                else {
                    layer.error(res.msg);
                }
            }, 'json');

            return false;
        })
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList",
            where: {
                agentid: "{:input('agentid/d',0)}"
            }
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                {
                    field: 'type', align: 'center', width: 100, templet: function (d) {
                        var text = '';
                        if (d.type == 1) {
                            text = '<span class="layui-badge layui-bg-blue">全国代理</span>';
                        }
                        if (d.type == 2) {
                            text = '<span class="layui-badge layui-bg-orange">城市代理</span>';
                        }
                        if (d.type == 3) {
                            text = '<span class="layui-badge layui-bg-green">区域代理</span>';
                        }
                        if (d.type == 4) {
                            text = '<span class="layui-badge layui-bg-cyan">街道代理</span>';
                        }
                        if (d.type == 5) {
                            text = '<span class="layui-badge layui-bg-red">划分代理</span>';
                        }
                        return text;

                    }, title: '类型'
                },
                { field: 'agent_name', align: 'center', width: 120, title: '代理' },
                { field: 'province_list', width: 150, align: 'center', title: '省份' },
                { field: 'city_list', width: 150, align: 'center', title: '城市' },
                { field: 'area_list', width: 150, align: 'center', title: '区县' },
                { field: 'street_list', width: 150, align: 'center', title: '街道' },
                { field: 'created', width: 150, align: 'center', title: '添加时间' },
                { align: 'center', toolbar: '#tableBar', width: 200, title: '操作' },
            ]]
        })
    })
</script>
</body>